local shijuan = fk.CreateSkill {
  name = "th_shijuan",
}

shijuan:addEffect(fk.DetermineDamageInflicted, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(shijuan.name) and (target == player or player:inMyAttackRange(target))
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function(p) return p:getMark("_th_shijuan_null-round") == 0 end)
    local to = player.room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#th_shijuan-invoke::"..target.id,
      skill_name = shijuan.name,
      cancelable = true
    })
    if #to == 1 then
      event:setCostData(self, { tos = to })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = event:getCostData(self)
    local to = dat.tos[1]
    if to ~= player and to ~= target then
      room:notifySkillInvoked(player, shijuan.name, "offensive")
    else
      room:notifySkillInvoked(player, shijuan.name, "defensive")
    end
    data:preventDamage()
    room:setPlayerMark(to, "_th_shijuan_null-round", 1)
    room:loseHp(to, 1, shijuan.name)
    if to ~= player and to ~= target then
      room:loseHp(player, 1, shijuan.name)
    end
  end
})

Fk:loadTranslationTable{
  ["th_shijuan"] = "饰卷",
  [":th_shijuan"] = "当你或你攻击范围内的角色受到伤害时，你可以防止之并令一名本轮未选择过的角色失去1点体力；若不为你或其，你失去1点体力。",

  ["#th_shijuan-invoke"] = "饰卷：你可以防止对 %dest 造成的伤害并令一名本轮未选择过的角色失去1点体力",
}

return shijuan